// 导入路由依赖
import { RouteObject, useRoutes } from "react-router-dom";

import { RouteType } from "@/types/route";
import routes from "@/router/router";
// 创建路由

function disposeRoute(list: RouteType[]): RouteObject[] {
	return list.map((item) => {
		// 拼接路径
		return {
			path: item.path,
			label: item.label,
			meta: item.meta,
			element: item.element,
			children: item.children ? disposeRoute(item.children) : undefined
		};
	});
}
const routesList = disposeRoute(routes);
console.log(routesList);

// 使用useRoutes 创建
export function RouterView() {
	// 创建路由
	const elem = useRoutes(routesList);
	// 返回接口
	return elem;
}
